﻿using System.Text;
using System;
using System.Xml;


namespace ExamSharedClasses
{   
    /// <summary>
    /// (k) Die Klasse Address soll die Adressdaten neben den von UserAddress
    /// geerbten Membern enthalten.
    /// </summary>
    [Serializable()]
    public class UserAddress : UserDetails
    {
        new public const string TABLENAME = "address";
        public const string ADDRESS_USER_ID = "user_id";
        public const string ADDRESS_CITY_ID = "address_city_id";
        public const string ADDRESS_COUNTRY_ID = "address_country_id";
        public const string ADDRESS_STREETNAME = "address_streetname";
        public const string ADDRESS_STREETNUMBER = "address_street_number";
        public const string ADDRESS_POSTAL_CODE = "address_postal_code";

        /// <summary>
        /// Eine City-Objekt-Referenz
        /// </summary>
        public City AddressCity { get; set; }
        /// <summary>
        /// Eine Country-Objekt-Referenz
        /// </summary>
        public Country AddressCountry { get; set; }
        /// <summary>
        /// Die Postleitzahl
        /// </summary>
        public string AddressPostalCode { get; set; }
        /// <summary>
        /// Straßenname
        /// </summary>
        public string AddressStreetName { get; set;}
        /// <summary>
        /// Hausnummer
        /// </summary>
        public string AddressStreetNumber { get; set; }

        public UserAddress() : base()
        {
            this.UserId = -1;
            this.AddressCity = new City();
            this.AddressCountry = new Country();
            this.AddressPostalCode = "";
            this.AddressStreetName = "";
            this.AddressStreetNumber = "";
        }
        public UserAddress(int userId, City addressCity, Country addressCountry, string addressPostalCode, string addressStreetName, string addressStreetNumber)
        : base() {
            this.UserId = userId;
            this.AddressCity = addressCity;
            this.AddressCountry = addressCountry;
            this.AddressPostalCode = addressPostalCode;
            this.AddressStreetName = addressStreetName;
            this.AddressStreetNumber = addressStreetNumber;
        }
        public UserAddress( UserDetails ud ) : base(ud) {
            this.UserId = -1;
            this.AddressCity = new City();
            this.AddressCountry = new Country();
            this.AddressPostalCode = "";
            this.AddressStreetName = "";
            this.AddressStreetNumber = "";
        }

        public override string ToString() {
            StringBuilder sb = new StringBuilder( base.ToString() + "Address: " );
            if ( AddressStreetName != null )
                sb.Append( "Strasse: " + AddressStreetName.ToString() + ' ' );
            if ( AddressStreetNumber != null )
                sb.Append( "Nr.: " + AddressStreetNumber.ToString() + '\n' );
            if ( AddressPostalCode != null )
                sb.Append( "PLZ: " + AddressPostalCode.ToString() + '\n' );
            if ( AddressCity != null )
                sb.Append( AddressCity.ToString() );
            if ( AddressCountry != null )
                sb.Append( AddressCountry.ToString() );
            return sb.ToString();
        }
        public override string ToMoreDetailedString() {
            StringBuilder sb = new StringBuilder( base.ToMoreDetailedString() + "Adresse:\n" );
            if ( AddressStreetName != null && AddressStreetNumber != null)
                sb.Append( "Strasse: " + AddressStreetName.ToString() + ' '+ AddressStreetNumber.ToString() + '\n' );
            if ( AddressPostalCode != null )
                sb.Append( AddressPostalCode.ToString() + ' ' );
            if ( AddressCity != null )
                sb.Append( AddressCity.CityName + '\n');
            if ( AddressCountry != null )
                sb.Append( AddressCountry.CountryName + '\n' );
            return sb.ToString();
        }
    }
}
